﻿@namespace Microsoft.FluentUI.AspNetCore.Components
@inherits FluentComponentBase

@if (Open)
{
    <FluentOverlay @bind-Visible="@Open" OnClose="@CloseAsync" Transparent=true FullScreen=true />
    @if (CloseKeys != null && CloseKeys.Any())
    {
        // Button or AnchorId element
        if (!string.IsNullOrEmpty(AnchorId))
        {
            <FluentKeyCode Anchor="@AnchorId" Only="@CloseAndTabKeys" OnKeyDown="@CloseOnKeyAsync" PreventDefaultOnly="@(AutoFocus ? CloseAndTabKeys : CloseKeys)" />
        }
        // Popover content
        if (!string.IsNullOrEmpty(Id))
        {
            <FluentKeyCode Anchor="@Id" Only="@CloseAndTabKeys" OnKeyDown="@CloseOnKeyAsync" PreventDefaultOnly="@CloseAndTabKeys" />
        }
    }
    <FluentAnchoredRegion @ref="AnchoredRegion"
                          Id="@Id"
                          Anchor="@AnchorId"
                          HorizontalInset="@HorizontalInset"
                          HorizontalDefaultPosition="@HorizontalPosition"
                          VerticalDefaultPosition="@VerticalPosition"
                          VerticalThreshold="@VerticalThreshold"
                          HorizontalThreshold="@HorizontalThreshold"
                          FixedPlacement="@FixedPlacement"
                          AutoFocus="@AutoFocus"
                          Shadow="@ElevationShadow.Flyout"
                          Class="@ClassValue"
                          Style="@StyleValue">
        <FluentStack Orientation="Orientation.Vertical">
            <div class="fluent-popover-content">
                @if (Header is not null)
                {
                    <div part="header">@Header</div>
                }
                @if (Body is not null)
                {
                    <div part="body">@Body</div>
                }
                @if (Footer is not null)
                {
                    <div part="footer">@Footer</div>
                }
            </div>
        </FluentStack>
    </FluentAnchoredRegion>
}
